/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.dialog;

import java.awt.Frame;

/**
 *
 * @author Shaman
 */
public class MessageBox {

    public enum DialogResult
    {
        OK,
        NO,
        CANCEL,
        YES,
        RETRY,
        ABORT,
        TIME_ELAPSED
    }

    public enum DialogButtons
    {
        OK,
        OkCancel,
        YesNo,
        YesNoCancel,
        RetryAbort
    }

    public enum DialogIcon
    {
        ERROR,
        INFORMATION,
        WARNING,
        QUESTION
    }

    public static DialogResult show(Frame parent, String message, String caption, DialogButtons buttons, DialogIcon icon)
    {
        MessageBoxDialog dialogForm = new MessageBoxDialog(parent, true);
        dialogForm.setTitle(caption);
        dialogForm.setLocationRelativeTo(parent);
        //Выставляем иконку
        dialogForm.setIcon(icon);
        //Выставляем видимость кнопок диалога
        dialogForm.okButton.setVisible(
            buttons.equals(DialogButtons.OK) ||
            buttons.equals(DialogButtons.OkCancel));
        dialogForm.yesButton.setVisible(
            buttons.equals(DialogButtons.YesNo) ||
            buttons.equals(DialogButtons.YesNoCancel));
        dialogForm.noButton.setVisible(
            buttons.equals(DialogButtons.YesNo) ||
            buttons.equals(DialogButtons.YesNoCancel));
        dialogForm.retryButton.setVisible(
            buttons.equals(DialogButtons.RetryAbort));
        dialogForm.abortButton.setVisible(
            buttons.equals(DialogButtons.RetryAbort));
        dialogForm.cancelButton.setVisible(
            buttons.equals(DialogButtons.OkCancel) ||
            buttons.equals(DialogButtons.YesNoCancel));
        
        dialogForm.setMessage(message);
        //Отображаем диалог
        dialogForm.setVisible(true);
        return dialogForm.getReturnStatus();
    }

    public static DialogResult show(Frame parent, String message, String caption, DialogButtons buttons)
    {
        return show(parent, message, caption, buttons, DialogIcon.INFORMATION);
    }

    public static DialogResult show(Frame parent, String message, String caption)
    {
        return show(parent, message, caption, DialogButtons.OK);
    }

    public static DialogResult show(Frame parent, String message)
    {
        return show(parent, message, "Сообщение");
    }

    public static void main(String[] args)
    {
        System.out.println(show(null, "ERROR: It works!!! Very Very Very Very Very Very Very Very Very Very Long message.", "ERROR", DialogButtons.OK).toString());
    }

}
